<?php

/**
 * This is the model class for table "zy_bonus".
 *
 * The followings are the available columns in table 'zy_bonus':
 * @property integer $id
 * @property integer $package_id
 * @property string $package_price
 * @property string $sale_time
 * @property integer $user_id
 * @property string $rate
 * @property string $bonus
 * @property integer $is_delelte
 * @property integer $user_service_id
 * @property integer $agent_number
 * @property integer $company_number
 */
class Bonus extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Bonus the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'zy_bonus';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('package_price, rate, bonus', 'required'),
			array('package_id, user_id, is_delelte, user_service_id, agent_number, company_number', 'numerical', 'integerOnly'=>true),
			array('package_price, rate, bonus', 'length', 'max'=>11),
			array('sale_time', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, package_id, package_price, sale_time, user_id, rate, bonus, is_delelte, user_service_id, agent_number, company_number', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'package_id' =>Yii::t('base','Package Name'),
			'package_price' => Yii::t('base','Package Price'),
			'sale_time' => Yii::t('base','Sale Time'),
			'user_id' => Yii::t('base','User Name'),
			'rate' => Yii::t('base','Rate'),
			'bonus' => Yii::t('base','Bonus'),
			'is_delelte' => 'Is Delelte',
			'user_service_id' => 'User Service',
			'agent_number' =>Yii::t('base','Agent Number'),
			'company_number' =>Yii::t('base','Company Number'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('package_id',$this->package_id);
		$criteria->compare('package_price',$this->package_price,true);
		$criteria->compare('sale_time',$this->sale_time,true);
		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('rate',$this->rate,true);
		$criteria->compare('bonus',$this->bonus,true);
		$criteria->compare('is_delelte',$this->is_delelte);
		$criteria->compare('user_service_id',$this->user_service_id);
		$criteria->compare('agent_number',$this->agent_number);
		$criteria->compare('company_number',$this->company_number);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	public function search2()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
	
		if($_GET['Rebatecommission']!=""){
			$agent_company_id=$_GET['Rebatecommission']['agent_company_id'];
			$agentcompany=AgentCompany::model()->find('agent_id='.$agent_company_id);
			$company_number=$agentcompany->agent_number;die();
		}
	}
}